package com.bootdo.coach.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.coach.dao.TabAgentMapper;
import com.bootdo.coach.dao.ext.ExtTabAgentMapper;
import com.bootdo.coach.domain.TabAgent;
import com.bootdo.coach.service.TabAgentService;
import com.bootdo.coach.vo.TabAgentVo;


@Service
public class TabAgentServiceImpl implements TabAgentService {
    @Autowired
    private TabAgentMapper mapper;
    @Autowired
    private ExtTabAgentMapper extMapper;

	@Override
	public int deleteByPrimaryKey(Long agentId) {
		return mapper.deleteByPrimaryKey(agentId);
	}

	@Override
	public int insert(TabAgent record) {
		return mapper.insert(record);
	}

	@Override
	public int insertSelective(TabAgent record) {
		return mapper.insertSelective(record);
	}

	@Override
	public TabAgent selectByPrimaryKey(Long agentId) {
		return mapper.selectByPrimaryKey(agentId);
	}

	@Override
	public int updateByPrimaryKeySelective(TabAgent record) {
		return mapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(TabAgent record) {
		return mapper.updateByPrimaryKey(record);
	}
	
	@Override
	public TabAgent findAgent(String bg_account, String bg_password) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("bg_account", bg_account);
		paramMap.put("bg_password", bg_password);
		return extMapper.findAgent(paramMap);
	}

	@Override
	public int count(Map<String, Object> query) {
		return extMapper.count(query);
	}

	@Override
	public List<TabAgentVo> list(Map<String, Object> query) {
		return extMapper.list(query);
	}
    
	@Override
	public boolean exitAgentName(Map<String, Object> params) {
		boolean exit;
        exit = extMapper.list(params).size() > 0;
        return exit;
	}
	
	@Override
	public boolean exitBgAccount(Map<String, Object> params) {
		boolean exit;
        exit = extMapper.list(params).size() > 0;
        return exit;
	}
	
	@Override
	public void updateAgentLevelAndHigherAgentId(Long agentId, Long higherAgentId) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("higherAgentId", higherAgentId);
		paramMap.put("agentId", agentId);
		extMapper.updateAgentLevelAndHigherAgentId(paramMap);
	}

	@Override
	public boolean exitAgentByAgentId(Long agentId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("agentId", agentId);
		boolean exit;
        exit = extMapper.count(params) > 0;
        return exit;
	}
	
	@Override
	public void updateAgentHigherAgentId(Long agentId, Long changeAgentId) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("higherAgentId", changeAgentId);
		paramMap.put("agentId", agentId);
		extMapper.updateAgentHigherAgentId(paramMap);
	}
	
	@Override
	public void updatePwd(String bg_account, String bg_password) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("bg_account", bg_account);
		paramMap.put("bg_password", bg_password);
		extMapper.updatePwd(paramMap);
	}
	
	@Override
	public Set<Long> findAgentIdList(Set<Long> agentIdList) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("agentIdList", agentIdList);
		return extMapper.findAgentIdList(paramMap);
	}
}
